//
//  SLUserManager.m
//  StarLight
//
//  Created by Duke.wu on 16/5/11.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLNetWork.h"
#import "SLUserManager.h"



@implementation SLUserManager
+ (void)storeUserInfoWithObject:(id)object andKey:(NSString *)key{
  
  [DEFAULTS setObject:object forKey:key];
  [DEFAULTS synchronize];
  [SLUserManager loginSuccess];
}

+ (void)loginSuccess{
  [DEFAULTS setBool:YES forKey:@"isLogined"];
  [DEFAULTS synchronize];
}

// 退出登录
+ (void)loginOut{
  [DEFAULTS setBool:NO forKey:@"isLogined"];
  [DEFAULTS synchronize];
  [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationRootVCToLoginVC object:nil];
}

+ (void)bindCid:(NSString *)cid{
  NSString *postUrl = [NSString backUrlWithService:@"user" methodName:@"bindcid"];
  if([DEFAULTS objectForKey:loginInfo][@"id"] != nil && cid != nil){
    NSDictionary *para = @{@"uid":[DEFAULTS objectForKey:loginInfo][@"id"],@"cid" :cid};
    [SLNetWork postDataWithParameters:para postUrl:postUrl complete:^(id respond, NSError *error) {
      DLog(@"%@",respond);
    }];
  }
  
}

+ (void)checkVersionSuccess:(VersionBlock)block{
  NSString *posturl = [NSString backUrlWithService:@"sys" methodName:@"version"];
  NSDictionary *para = @{@"uid":[DEFAULTS objectForKey:loginInfo][@"id"], @"version" : kVerSion};
  [SLNetWork postDataWithParameters:para postUrl:posturl complete:^(id respond, NSError *error) {
    if (!error) {
      
      NSString  *version = respond[@"version"][@"version"];
      block(version);
    }
  }];
}


@end
